{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "4ee9e704",
   "metadata": {},
   "source": [
    "----\n",
    "* 时间:2022/10/17 week09"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "43d09831",
   "metadata": {},
   "source": [
    "# 本周知识点\n",
    "> 1. 用户输入\n",
    "> 2. 文本的格式化输出"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "382789f9",
   "metadata": {},
   "source": [
    "## 1. 用户输入\n",
    "* input方法"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "bec3b358",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "账号:admn\n",
      "密码:dadda\n"
     ]
    }
   ],
   "source": [
    "# 用户登录系统\n",
    "username =input(\"账号:\")\n",
    "password =input(\"密码:\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "d9d69784",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "admn\n",
      "dadda\n"
     ]
    }
   ],
   "source": [
    "print(username)\n",
    "print(password)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "5fe14b52",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "账号:dadadad\n",
      "密码:daadda\n",
      "账号不存在或密码不正确，请重新输入\n"
     ]
    }
   ],
   "source": [
    "# 用户登录系统 迭代1\n",
    "user01=\"admin\"\n",
    "password=\"123456\"\n",
    "username =input(\"账号:\")\n",
    "password =input(\"密码:\")\n",
    "# 情景一：账号密码都正确\n",
    "if user01 == username and password == password:\n",
    "    print(\"登录成功·欢迎\"+user01)\n",
    "else:\n",
    "    print(\"账号不存在或密码不正确，请重新输入\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "586a6e8e",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 用户登录系统迭代2 循环 for+range\n",
    "user01=\"admin\"\n",
    "password=\"123456\"\n",
    "for i in range(3):\n",
    "    username =input(\"账号:\")\n",
    "    password =input(\"密码:\")\n",
    "# 情景一：账号密码都正确\n",
    "    if user01 == username and password == password:\n",
    "        print(\"登录成功·欢迎\"+user01)\n",
    "    else:\n",
    "        print(\"账号不存在或密码不正确，请重新输入\")\n",
    "    \n",
    "    \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "5a558f2c",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "id": "95d68781",
   "metadata": {},
   "source": [
    "## 2.字符串的格式化输出\n",
    "> 1. 字符串的拼接\n",
    "> 2. 占位符\n",
    "> 3. 格式化输出: format()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "c3262308",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "昵称：dada\n",
      "地区：adae\n",
      "工作：eeee\n",
      "年龄：ffff\n",
      "期待薪资：fffyy\n"
     ]
    }
   ],
   "source": [
    "# 用户的信息输入(完善信息)\n",
    "name = input (\"昵称：\")\n",
    "region = input (\"地区：\")\n",
    "job = input (\"工作：\")\n",
    "age = input (\"年龄：\")\n",
    "salary = input (\"期待薪资：\")\n",
    "\n",
    "info='''-----------INFO'''+ name +'''---------\n",
    "地区：'''+ region + '''\n",
    "工作：'''+ job + '''\n",
    "年龄：'''+ age + '''\n",
    "期待薪资：'''+salary\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "7158b6dc",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "-----------INFOdada---------\n",
      "地区：adae\n",
      "工作：eeee\n",
      "年龄：ffff\n",
      "期待薪资：fffyy\n"
     ]
    }
   ],
   "source": [
    "print(info)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "bd2f0c68",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "昵称：22\n",
      "地区：33\n",
      "工作：33\n",
      "年龄：33\n",
      "期待薪资：333\n",
      "---------INFO 22 --------\n",
      "地区：33 \n",
      "工作：33 \n",
      "年龄：33\n",
      "薪资期待：333 \n"
     ]
    }
   ],
   "source": [
    "# 用户的信息输入（完善信息） : 占位符 s%\n",
    "name = input(\"昵称：\")\n",
    "region = input(\"地区：\")\n",
    "job = input(\"工作：\")\n",
    "age = input(\"年龄：\")\n",
    "salary = input(\"期待薪资：\")\n",
    "\n",
    "info = '''---------INFO %s --------\n",
    "地区：%s \n",
    "工作：%s \n",
    "年龄：%s\n",
    "薪资期待：%s '''%(name,region,job,age,salary)\n",
    "print(info)\n",
    "# 局限性：有序，个数确定，不能乱写"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "bb9c0083",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "昵称：你好\n",
      "地区：广东\n",
      "工作：d\n",
      "年龄：20\n",
      "期待薪资：8k\n",
      "---------INFO 你好 --------\n",
      "地区：广东\n",
      "工作：d \n",
      "年龄：20\n",
      "薪资期待：8k \n"
     ]
    }
   ],
   "source": [
    "# 用户的信息输入（完善信息） : format()\n",
    "name = input(\"昵称：\")\n",
    "region = input(\"地区：\")\n",
    "job = input(\"工作：\")\n",
    "age = input(\"年龄：\")\n",
    "salary = input(\"期待薪资：\")\n",
    "\n",
    "info = '''---------INFO {昵称} --------\n",
    "地区：{地区}\n",
    "工作：{工作职位} \n",
    "年龄：{年龄}\n",
    "薪资期待：{薪资} '''.format(工作职位=job,薪资=salary,昵称=name,年龄=age,地区=region)\n",
    "print(info)\n",
    "# 书写规范，字符串中的 字段 一一对应，不考虑其顺序"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "0d55a931",
   "metadata": {},
   "source": [
    "## 课后作业：第二章p93 前所有项目练习（下周讲）\n",
    "> 1. 第二章p93 前所有项目练习（下周讲）\n",
    "> 2. 购物车项目\n",
    ">>1. 运行程序后，让用户输入支付宝余额，然后打印我们的商品列表给用户。\n",
    ">>2. 让用户输入商品编号进行商品的购买。\n",
    ">>3. 用户选择商品后，检查用户的余额是否够，若够则直接扣款，不够则提醒用户。  \n",
    ">>4. 用户可以随时退出购买，推出时打印用户已购买的商品和支付宝余额。\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "19e4705c",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "i\n",
      "i\n",
      "a\n"
     ]
    }
   ],
   "source": [
    "# p60\n",
    "vowels = ['a','e','i','o','u']\n",
    "word=\"milliways\"\n",
    "found = []\n",
    "for letter in word:\n",
    "    if letter in vowels:\n",
    "         found.append(letter)\n",
    "for vowel in found:\n",
    "    print(vowel)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "12bc0a0d",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "provide a word to search for vowels:apple\n",
      "a\n",
      "e\n"
     ]
    }
   ],
   "source": [
    "# p61\n",
    "vowels = ['a','e','i','o','u']\n",
    "word = input(\"provide a word to search for vowels:\")\n",
    "found = []\n",
    "for letter in word:\n",
    "    if letter in vowels:\n",
    "        if letter not in found:\n",
    "            found.append(letter)\n",
    "for vowel in found:\n",
    "    print(vowel)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "be1885fe",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Don't panic!\n",
      "['D', 'o', 'n', \"'\", 't', ' ', 'p', 'a', 'n', 'i', 'c', '!']\n",
      "['o', 'n', ' ', 't', 'a', 'p']\n",
      "on tap\n"
     ]
    }
   ],
   "source": [
    "# 83\n",
    "phrase = \"Don't panic!\"\n",
    "plist = list(phrase)\n",
    "print(phrase)\n",
    "print(plist)\n",
    "\n",
    "for i in range(4):\n",
    "    plist.pop()\n",
    "plist.pop(0)\n",
    "plist.remove(\"'\")\n",
    "plist.extend([plist.pop(),plist.pop()])\n",
    "plist.insert(2,plist.pop(3))\n",
    "\n",
    "new_phrase = ''.join(plist)\n",
    "print(plist)\n",
    "print(new_phrase)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "bd87ec7d",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Don't panic!\n",
      "['D', 'o', 'n', \"'\", 't', ' ', 'p', 'a', 'n', 'i', 'c', '!']\n",
      "['D', 'o', 'n', \"'\", 't', ' ', 'p', 'a', 'n', 'i', 'c', '!']\n",
      "Don't panic!\n"
     ]
    }
   ],
   "source": [
    "# 83\n",
    "phrase = \"Don't panic!\"\n",
    "plist = list(phrase)\n",
    "print(phrase)\n",
    "print(plist)\n",
    "\n",
    "new_phrase = ''.join(plist[1:3])\n",
    "new_phrase = new_phrase+ ''.join([plist[5],plist[4],plist[7],plist[6]])\n",
    "\n",
    "print(plist)\n",
    "print(phrase)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "2fcaeabd",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\t a\n",
      "\t p\n",
      "\t p\n",
      "\t l\n",
      "\t e\n"
     ]
    }
   ],
   "source": [
    "# 86\n",
    "paranoid_android=\"apple\"\n",
    "letters= list(paranoid_android)\n",
    "for char in letters:\n",
    "    print('\\t',char)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "9fc0f5f5",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\t a\n",
      "\t p\n",
      "\t p\n",
      "\t l\n",
      "\t e\n",
      "\n",
      "\t\t a\n",
      "\t\t n\n",
      "\t\t d\n",
      "\t\t r\n",
      "\t\t o\n",
      "\t\t i\n",
      "\t\t d\n",
      "\n",
      "\t\t\t p\n",
      "\t\t\t a\n",
      "\t\t\t r\n",
      "\t\t\t a\n",
      "\t\t\t n\n",
      "\t\t\t o\n",
      "\t\t\t i\n",
      "\t\t\t d\n"
     ]
    }
   ],
   "source": [
    "# P87\n",
    "paranoid_android=\"apple,the paranoid android\"\n",
    "letters = list(paranoid_android)\n",
    "for char in letters[ :5]:\n",
    "    print('\\t',char)\n",
    "print()\n",
    "for char in letters[-7:]:\n",
    "    print('\\t'*2,char)\n",
    "print()\n",
    "for char in letters[10:18]:\n",
    "    print('\\t'*3,char)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7d46bf06",
   "metadata": {},
   "source": [
    "## 购物车项目"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "7e9eeef6",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "余额:80\n",
      "1 ('apple', 50)\n",
      "2 ('pear', 30)\n",
      "3 ('pen', 20)\n",
      "你要买的商品的序号为:\n",
      "商品:1\n",
      "30\n",
      "---------INFO  --------\n",
      "余额: 80\n",
      "商品：1 \n"
     ]
    }
   ],
   "source": [
    "money=int(input(\"余额:\"))\n",
    "\n",
    "商品list=[('apple',50),('pear',30),('pen',20)]\n",
    "for index, item in enumerate(商品list):\n",
    "    print(index + 1, item)\n",
    "print(\"你要买的商品的序号为:\")\n",
    "want=int(input(\"商品:\"))\n",
    "    \n",
    "if want==1 and money-50>=0:\n",
    "     print(money-50)\n",
    "elif want==2 and money-30>=0:\n",
    "      print(money-30)\n",
    "elif want==3 and money-20>=0:\n",
    "     print(money-20,)\n",
    "        \n",
    "else:\n",
    "    print(\"余额不足\")\n",
    "\n",
    "\n",
    "info = '''---------INFO  --------\n",
    "余额: %s\n",
    "商品：%s '''%(money,want)\n",
    "print(info)\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a7c39152",
   "metadata": {},
   "outputs": [],
   "source": [
    "\n",
    "\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
